{include file="public/header" /}
<body>
    <div class="pd-20">
        <form action="" method="post" class="form form-horizontal" id="form-member-add">
            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>账号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$row.username|default=''}" placeholder="username" name="username" datatype="*" nullmsg="请输入账号" {if condition="isset($row.id) && $row.id gt 0"}disabled{/if} >
                </div>
                <div class="col-4" id="error"> </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" value="" name="password" 
                    {if condition="isset($row['id']) && $row['id'] gt 0"}placeholder="填写为修改"{else/}datatype="*" placeholder="password" nullmsg="请输入密码"{/if}>
                </div>
                <div class="col-4"> </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>昵称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$row.nickname|default=''}" name="nickname" datatype="*" nullmsg="请输入昵称" placeholder="nickname"  nullmsg="请输入昵称">
                </div>
                <div class="col-4"> </div>
            </div>

            {if condition="isset($role) and $role"}
            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>角色：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    {foreach name="$role" item="v"}
                    <div class="check-box">
                        <input type="checkbox" id="role-{$v.id}" value="{$v.id}" name="role[]" 
                        {if condition="in_array($v['id'],$row['roles'])"}checked{/if} >
                        <label for="role-{$v.id}">{$v.title}</label>
                    </div>
                    {/foreach}
                </div>
                <div class="col-4"> </div>
            </div>
            {/if}
            <div class="row cl">
                <div class="col-9 col-offset-3">
                    <input type="hidden" value="{$row.id|default=''}" name="id">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </div>

{include file="public/footer" /}
<script type="text/javascript">
//选择框
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});

    $("#form-member-add").validate({
        rules:{
            username:{
                required:true,
                maxlength:16
            },
        },
        onkeyup:false,
        focusCleanup:true,
        success:"valid",
        submitHandler:function(form){
            $(form).ajaxSubmit({
                success:function(data){
                    console.log(data);
                    if(data.status == 'y'){
                        layer.msg("操作成功",{icon:1,time:1000,shade: [0.3, '#000']},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(data.info,{icon:2,time:1000,shade: [0.3, '#000']});
                    }
                },
                error:function(error){
                    layer.msg('系统发生了错误',{icon:2,time:3000,shade: [0.5, '#FF0000']});
                }
            });

        }
    });
   $("input[name='username']").blur(function(){
        var username = $.trim($(this).val());
        if(username == ''){
          return false;
        }
        $.post("{:url('repeat')}",{repeat:username},function(data){
          if(data.status == 'n'){
            $("#error").html("<span style='color:red;'>此账号已被使用</span>");
          }else{
            $("#error").html("<span style='color:#75d201;'>此账号可以使用</span>");
          }
      });
   });
});
</script>
</body>
</html>